package com.zzptc.lxy.mybook;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PersonalActivity extends AppCompatActivity {
    private LinearLayout Lv_username, Lv_nickname, Lv_introduce;
    private TextView username, nickname, introduce;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal);
        initView();

        setListener();

    }

    private void setListener() {
//用户名
        Lv_username.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

//昵称
        Lv_nickname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final View v = LayoutInflater.from(PersonalActivity.this).inflate(R.layout.popup, null);

                AlertDialog.Builder builder = new AlertDialog.Builder(PersonalActivity.this)
                        .setIcon(R.mipmap.pen)
                        .setTitle("修改昵称")
                        .setView(v)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                EditText edit_dialog = v.findViewById(R.id.edit_dialog);//实例化
                                nickname.setText(edit_dialog.getText().toString());//获取输
                            }
                        });
                builder.create().show();
            }
        });
//        签名
        Lv_introduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final View v = LayoutInflater.from(PersonalActivity.this).inflate(R.layout.popup, null);

                AlertDialog.Builder builder = new AlertDialog.Builder(PersonalActivity.this)
                        .setIcon(R.mipmap.pen)
                        .setTitle("修改签名")
                        .setView(v)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                EditText edit_dialog = v.findViewById(R.id.edit_dialog);//实例化
                                introduce.setText(edit_dialog.getText().toString());//获取输
                            }
                        });
                builder.create().show();
            }
        });
    }

    private void initView() {

        Lv_username = findViewById(R.id.Lv_username);
        Lv_nickname = findViewById(R.id.Lv_nickname);
        Lv_introduce = findViewById(R.id.Lv_introduce);
        username = findViewById(R.id.username);
        nickname = findViewById(R.id.nickname);
        introduce = findViewById(R.id.introduce);
//        获取用户名
        SharedPreferences sp = getSharedPreferences("userinfo", Context.MODE_PRIVATE);
        String usn = sp.getString("username", "");
        username.setText(usn);

    }
}